﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AutoUpdater.Util
{
    public class ProcessUtil
    {
        public static string StartExePath
        {
            get
            {
                return System.Windows.Forms.Application.ExecutablePath;
            }
        }

        public static string StartExeFileName
        {
            get
            {
                return Process.GetCurrentProcess().MainModule.ModuleName;
                //return Process.GetCurrentProcess().MainModule.FileName;
            }
        }

        public static string StartProcessName
        {
            get
            {
                return Process.GetCurrentProcess().ProcessName;
            }
        }

        private static string baseDirectory;

        public static string BaseDirectory
        {
            get
            {
                if (!string.IsNullOrEmpty(baseDirectory))
                {
                    return baseDirectory;
                }

                if (StartExeFileName.EndsWith("AutoUpdater.exe"))
                {
                    DirectoryInfo baseDirectoryInfo = Directory.GetParent(Environment.CurrentDirectory);
                    baseDirectory = baseDirectoryInfo.FullName;
                }
                else
                {
                    baseDirectory = System.AppDomain.CurrentDomain.BaseDirectory;
                }

                return baseDirectory;
            }
        }

        public static string TempPath
        {
            get {  return Path.Combine(BaseDirectory, "tempUpdate"); }
        }
    }
}
